package com.seeyon.apps.nygj.dao.impl;

import com.seeyon.apps.nygj.dao.SyncUnFlowDataDao;
import com.seeyon.apps.nygj.po.SyncUnFlowDataPO;
import com.seeyon.ctp.common.exceptions.BusinessException;
import com.seeyon.ctp.util.DBAgent;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class SyncUnFlowDataDaoImpl implements SyncUnFlowDataDao {

    @Override
    public void saveSyncUnFlowDataPO(SyncUnFlowDataPO syncUnFlowDataPO) throws BusinessException {
        DBAgent.merge(syncUnFlowDataPO);
    }

    @Override
    public SyncUnFlowDataPO findSyncUnFlowDataPODataById(String state, String dataType) throws BusinessException {
        StringBuilder hql = new StringBuilder();
        Map<String, Object> params = new HashMap<String, Object>();
        hql.append(" FROM " + SyncUnFlowDataPO.class.getSimpleName());
        hql.append(" WHERE state = :state AND dataType = :dataType ORDER BY createTime DESC");
        params.put("state", state);
        params.put("dataType", dataType);
        List list = DBAgent.find(hql.toString(), params);
        if (list.size() > 0) {
            return (SyncUnFlowDataPO) list.get(0);
        } else {
            return null;
        }
    }
}
